<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class gallery extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/admin/Gallery
	 *	- or -  
	 * 		http://example.com/admin/Gallery/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/Gallery/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
	    $data["collections"] = $this->tdatabase->get_entry('collections');        
		$data["current_page"] = "gallery";        
		$this->parser->parse("admin/header.tpl", $data);
		$this->parser->parse("admin/gallery.tpl", $data);
		$this->parser->parse("admin/footer.tpl", $data);
	}
	
    public function deleteCollection($collID)
    {
        $this->collection->delete($collID);
    }
    
    public function deleteImage($imgID) 
    {
        $this->images->delete($imgID);
    }
    
    public function getImages($collID)
    {   
        echo json_encode(array("html" => $this->images->getHtmlBox($collID)));
    }
    
	public function uploadImage($collID)
	{
        $this->images->upload($collID);
        $this->collection->updateCover($collID);
	}
	
	public function getCollectionsInfo(&$data) {
		//TODO: create gallery COllection object
	}
	
	public function addCollection(){
		echo $this->collection->add();
	}
    
    public function updateImages($imgID) {
        $title = $this->input->post('title');
        $desc = $this->input->post('description');
        $this->images->update($imgID, $title, $desc);
    }

    public function getImageTexts($imgID) {
        $title = $this->images->getTitle($imgID);
        $desc = $this->images->getDescription($imgID);
        echo json_encode(array("title" => $title, "desc" => $desc));
    }
    
	public function __construct()
	{
		parent::__construct();
		$this->load->library('ion_auth');
		$this->load->library(array('encrypt', 'form_validation', 'session'));
		$this->load->model('tdatabase_model', 'tdatabase');
        $this->load->model('images_model', 'images');
        $this->load->model('collection_model', 'collection');
		// LOAD HELPERS
		$this->load->helper(array('form'));
		if (!$this->ion_auth->logged_in()) {
			redirect(site_url('auth'));
		}
	}
}

/* End of file Gallery.php */
/* Location: ./application/controllers/Gallery.php */
